package com.rdtravel.web;

import com.rdtravel.services.DepartureLocationsService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/departurelocations")
class DepartureLocationsController {
	private final DepartureLocationsService departureLocationsService;

	@Autowired
	public DepartureLocationsController(
			DepartureLocationsService departureLocationsService) {
		this.departureLocationsService = departureLocationsService;
	} 
	
	@RequestMapping(value = "names", method = RequestMethod.GET, params = "term", produces = MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody
	List<String> findNamesStartingWith(@RequestParam String term) {
		return departureLocationsService.findNamesStartingWith(term);
	}
	
	
}
